<?php

namespace App\Models;

use DateTimeInterface;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Traits\DefaultDatetimeFormat;
use Illuminate\Database\Eloquent\Model;

class Department extends Model
{
    use DefaultDatetimeFormat;

    public function users(): \Illuminate\Database\Eloquent\Relations\HasMany
    {
        return $this->hasMany(AdminUser::class, 'department_id');
    }

    public static function departmentOptions($admin = null): \Illuminate\Support\Collection
    {
        if (!$admin instanceof AdminUser) {
            $admin = Admin::user();
        }
        return self::query()->pluck('name', 'id');
    }

    public static function enabled(): bool
    {
        return config('department.enable') ?: false;
    }

    public static function enabledReview(): bool
    {
        return self::enabled() && config('department.review');
    }
}
